// pages/editAddress/editAddress.js
import Dialog from '@vant/weapp/dialog/dialog';
const $ = require("../../utils/util")
// import {areaList} from '@vant/weapp/dist/area-data/dist/index';
Page({

  /**
   * 页面的初始数据
   */
  data: {
		areaList:"",
		region: ['', '', ''],
		addressType:false,
		switchChecked: true,
		show: false,
		name:"",
		tel:"",//电话
		areaCode:"",//地址id
		isDefault:false,
		addressDetail:"",//详细地址
		postalCode:"",
		country:"",
	},
	showPopup() {
    this.setData({ show: true });
  },

  onClose() {
    this.setData({ show: false });
  },
	switchChange(){
		this.setData({
			isDefault:!this.data.isDefault
		})
	},
edited(){
	Dialog.confirm({
		message: '即将进行保存地址操作',
	})
		.then(() => {
			// on confirm
			console.log(this.data);
			$.axios({
				url:"address/save",
				method:"POST",
				header:{
					"X-Byesame-Token":wx.getStorageSync('token')
				},data:{
					addressDetail:this.data.addressDetail,
					areaCode:this.data.areaCode,
					city:this.data.region[1],
					country:this.data.country,
					county:this.data.region[2],
					isDefault:this.data.isDefault,
					name:this.data.name,
					postalCode:"",
					province:this.data.region[0],
					tel:this.data.tel
				}
			}).then(res=>{
				console.log(res,"res");
				wx.navigateBack()
			})
		})
		.catch(() => {
			// on cancel
		});
},
editdel(){
	Dialog.confirm({
		message: '确定删除地址操作？',
	})
		.then(() => {
			// on confirm
			$.axios({
				url:"address/delete",
				method:"POST",
				header:{
					"X-Byesame-Token":wx.getStorageSync('token')
				},
				// data:{
				// 	addressDetail:this.data.addressDetail,
				// 	areaCode:this.data.areaCode,
				// 	city:this.data.region[1],
				// 	country:this.data.country,
				// 	county:this.data.region[2],
				// 	isDefault:this.data.isDefault,
				// 	name:this.data.name,
				// 	postalCode:"",
				// 	province:this.data.region[0],
				// 	tel:this.data.tel
				// }
			}).then(res=>{
				console.log(res,"res");
				wx.navigateBack()
			})
			
		})
		.catch(() => {
			// on cancel
		});
},

	bindRegionChange: function (e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
			region: e.detail.value,
			addressType:true,
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})